let db = require('../db/index')


exports.adminlogo = (req, res) => {
  //  var name=req.query.name
  //  var psw=req.query.psw
  //  console.log(name)
  //  console.log(psw)
  var sql = 'select * from admin where name = ? and psw = ?'
  db.query(sql, [req.query.name, req.query.psw], (err, data) => {
    if (err) {
      return res.send({
        status: 400,
        message: "登录失败"
      })
    }
    if (data.length > 0) {
      res.send({
        status: 200,
        message: "登录成功"
      })
    } else {
      res.send({
        status: 202,
        message: '用户名或密码错误'
      })
    }

  })
}
exports.index = (req, res) => {
  var sql = 'select * from wenzhang'
  db.query(sql , (err, data) => {
    if (err) {
      return res.send(err.message)
    }
    //console.log(data)
    res.send(data)

  })
}
exports.datails = (req, res) => {
  var sql = 'select * from wenzhang where wid = ?'
  db.query(sql  ,[req.query.wid], (err, data) => {
    if (err) {
      return res.send(err.message)
    }
     //console.log(data)
    res.send(data)

  })
}
exports.adminadd = (req, res) => {
  var title = req.body.title
  var html = req.body.html
  //  console.log(title)
  //  console.log(html)
  var sql = 'insert into wenzhang(title,content) values(?,?)'
  db.query(sql, [title, html], (err, data) => {
    if (err) {
      return res.send({
        status: 400,
        message: "失败"
      })
    } else {
      res.send({
        status: 200,
        message: '成功'
      })
    }

  })
}
